{% extends "PATHomeBundle::base.html.twig" %}
{% block title %}
	{{ parent() }} Edition de profil
{% endblock title %}

{% block head %}
{{ parent() }}
<script type="text/javascript">
jQuery(document).ready(function(){
	var collectionAddresses = $('ul.addresses');
	var $addLink = $('<a href=""><img src="/pokeshop/web/bundles/patwishlist/images/icone-pos.png" alt="Add" /></a>');
	collectionAddresses.before($addLink);
	collectionAddresses.find('li').each(function(){
		addDeleteLink($(this));
	});

	$addLink.on('click',function(e){
		e.preventDefault();
		var prototype = collectionAddresses.attr('data-prototype');

		var newForm = prototype.replace(/__name__/g,collectionAddresses.children().length);
		var $newFormLi = $('<li></li>').append(newForm);
		collectionAddresses.append($newFormLi);
		addDeleteLink($newFormLi);
	});
});

function addDeleteLink($formLi){
	var $remove = $('<a href="">Supprimer</a>');
	$formLi.append($remove);
	$remove.on('click', function(e){
		e.preventDefault();
		if(confirm("Confirmer la suppression ?"))$formLi.remove();
	});
}
</script>
{% endblock head %}

{% block body %}
<form action="{{ path('fos_user_profile_edit') }}" {{ form_enctype(form) }} method="POST" class="fos_user_profile_edit">
    <h1>Mise à jour du profil</h1>
    <div class="editUser">
        <div class="editUserInfo">
            <h2>Profil du Membre: </h2>
            {{ form_row(form.username, {"attr":{"readonly":""}}) }}
            {{ form_row(form.name, {"label":"Nom : "}) }}
            {{ form_row(form.firstname, {"label":"Prénom : "}) }}
            {{ form_row(form.email, {"label":"Email : "}) }}
            {{ form_row(form.telephone, {"label":"Téléphone : "}) }}
        </div>
            <div class="sacha_edit">
                <img src="../../pictures/design/sacha_edit.png" alt="sacha" />
            </div>
    </div>
    
    <div class="editAdress">
        <h2>Mes adresses :</h2>
        <ul class="addresses" data-prototype="{{ form_widget(form.addresses.vars.prototype)|e }}">
            {% for a in form.addresses %}
                    <li>{{ form_row(a.street,{"label":"Rue :"}) }}
                    {{ form_row(a.postalCode,{"label":"Code Postal :"}) }}
                    {{ form_row(a.city,{"label":"Ville :"}) }}
                    {{ form_row(a.country,{"label":"Pays :"}) }}</li>
            {% endfor %}
        </ul>
    </div>
    
    <div class="editConfirm">
         <p>Pour des raisons de sécurité, veuillez entrer votre mot de passe</p>
        {{ form_rest(form) }}
        <input class="generic_link" type="submit" value="{{ 'profile.edit.submit'|trans({}, 'FOSUserBundle') }}" />
    </div>
</form>
{% endblock body %}